home *** CD-ROM | disk | FTP | other *** search
/ Floppyshop 2 / Floppyshop - 2.zip / Floppyshop - 2.iso / art&graf.ix / art-5625 / 3d2-_pov.12 / source.c / cyb_pov.ruf < prev   
Text File  |  1995-10-15  |  10KB  |  255 lines

  1. /*
  2.                 Converts\ed Cybersculpt 3D2-Files in the  POV-Sourceformat.
  3.  
  4.                 (c) June 1994 Jochen Knaus
  5.                                                                         Nickeleshalde 19
  6.                                                                         88400 Biberach
  7.                                                                         07351 / 24483
  8.  
  9.                 date:                                27.7.1994
  10.                 Update:                                30.9.1994
  11.                 version:                        1.20
  12.  
  13.                 This Konvertierprogramm is Freeware, in the spirits of the  POV.
  14.                 Somewhen soon will(_be)'s to "smooth triangles" extends\ed.
  15.  
  16.                 opposite versions <=1.01 became the  Kommandozeilenformat altered.
  17.                 The  Files take (self) now too with POV 2.X (over option "-v2").
  18.                 
  19.                 It can now too a "bounded_by" optimisation  become generates\d.
  20.                 From version 1.2: Faster and small(er)...
  21.  
  22.                 call:        CYB_POV -s<source> -d<destin> -n<objektnamen> -v<povversion>
  23.                                                                                 -b<mode>
  24. */
  25.  
  26. #include<tos.H>
  27. #include<stdio.H>
  28. #include<string.H>
  29. #include<portab.H>
  30. #include<stdlib.H>
  31. #include<limits.H>
  32.  
  33. #define VERSION_A        1
  34. #define VERSION_B 2
  35. #define        PATHLEN        256+1
  36.  
  37. int        abbruch( void );
  38.  
  39. /* Filehandles global... */
  40. int source, destin;
  41.  
  42. int        main( int argc, char *argv[] )
  43. {
  44.         WORD                                        header[128], anz_obj, anz_dot, anz_facetten,
  45.                                                                 *dot, *facetten;
  46.         char                                        obj_name[10], buffer[2560], buffer2[256],
  47.                                                                 buffer3[4] = { '}', 13, 10, 0 },
  48.                                                                 def_file[PATHLEN] = "STD.POV", def_name[64] = "DEFOBJ",
  49.                                                                 source_file[PATHLEN], minus[2] = { '-', 0 }, nullos[2] = { 0 },
  50.                                                                 *vorzeichen[6];
  51.         register int        i, j, m;
  52.         int                                                pov_mode = 1, bounds = 0;                                        /* POV-version. */
  53.         int                                                wandel[6], minmax[6];
  54.  
  55.         puts( "" );
  56.         printf( "3D2->POV Converter vers. %d.%d, (c) 1994 by Jochen Knaus (AURA), Freeware.\n",
  57.                                         VERSION_A, VERSION_B );
  58.         puts( "" );
  59.  
  60.         if( argc <= 1 ) return( -1 );                                                                        /* No parameter(s) ? */
  61.  
  62.         for( i=1, source_file[0] = '\0' ; i < argc ; i++ )
  63.         {
  64.                 if( (argv[i])[0] == '-' )                                                                                /* parameter(s) ? */
  65.                 {
  66.                         switch( (argv[i])[1] )
  67.                         {
  68.                                 /* Zielfile ? */
  69.                                 case        'd':        strncpy( def_file, argv[i]+2, 127 ); break;
  70.                                 /* object names ? */
  71.                                 case        'n':        strncpy( def_name, argv[i]+2, 63 ); break;
  72.                                 /* Sourcefile ? */
  73.                                 case        's':        strncpy( source_file, argv[i]+2, 127 ); break;
  74.                                 /* POV-version ? */
  75.                                 case        'v':        pov_mode = (int) ((argv[i])[2] -'0'); break;
  76.                                 /* Grenzbox calculate. */
  77.                                 case        'b':        bounds = (int) ((argv[i])[2] -'0') ; break;
  78.                         }
  79.                 }
  80.         }
  81.  
  82.         if( strlen( source_file ) == 0 )                                                        /* No 3D2-File given ? */
  83.         { puts( "No source (3D2) file." );
  84.                 return( -1 ); }
  85.  
  86.         /* source file open. */
  87.         if( ( source = Fopen( source_file, FO_READ ) ) < 0 )
  88.         {        puts( "Cannot open sourcefile. ");
  89.                 return( source ); }
  90.  
  91.         /* destination file generate. */
  92.         if( ( destin = Fcreate( def_file, (int) 0 ) ) < 0 ) 
  93.         {        puts( "Cannot create destinationfile." );
  94.                 return( destin ); }
  95.  
  96.         /* Header read. */
  97.         if( Fread( source, (long) 256, header ) < 0 ) return( abbruch() );
  98.  
  99.         if( header[0] != 15618 )                                                                                         /* 3D2-File ? */
  100.         {        puts( "No 3D2 File..." );
  101.                 return( abbruch() ); }
  102.  
  103.         anz_obj = header[1];
  104.         printf( "%s: Convert %d object(s).\n\n", source_file, anz_obj );
  105.  
  106.         sprintf( buffer, "#declare %s = union {%s", def_name, &buffer3[1] );
  107.         Fwrite( destin, strlen(buffer), buffer );
  108.  
  109.         if( bounds != 0 )                                                                                                                        /* Grenzwerte initialise. */
  110.         {
  111.                 minmax[0] = INT_MAX; minmax[1] = INT_MIN;
  112.                 minmax[2] = INT_MAX; minmax[3] = INT_MIN;
  113.                 minmax[4] = INT_MAX; minmax[5] = INT_MIN;
  114.         }
  115.  
  116.         for( i=0 ; i<anz_obj ; i++ )                                                                        /* All objects ! */
  117.         {
  118.                 Fread( source, (long) 9, obj_name );                                /* object names */
  119.                 Fread( source, (long) 2, &anz_dot );
  120.  
  121.                 if( anz_dot > 0 )
  122.                 {
  123.                         /* memory for points reserve. */
  124.                         if( ( dot = malloc( (long) (anz_dot * 6) ) ) == NULL )
  125.                                 return( abbruch() );
  126.                         else
  127.                                 Fread( source, (long) anz_dot*3*2, dot ); /* points read in. */
  128.  
  129.                         if( bounds != 0 )                                                                                /* object borders secure ? */
  130.                         {
  131.                                 for( j = 0 ; j < anz_dot ; j++ )                /* Objektextremas festellen. */
  132.                                 {
  133.                                         if( dot[j*3+0] < minmax[0] ) minmax[0] = dot[j*3+0];
  134.                                         if( dot[j*3+0] > minmax[1] ) minmax[1] = dot[j*3+0];
  135.                                         if( dot[j*3+1] < minmax[2] ) minmax[2] = dot[j*3+1];
  136.                                         if( dot[j*3+1] > minmax[3] ) minmax[3] = dot[j*3+1];
  137.                                         if( dot[j*3+2] < minmax[4] ) minmax[4] = dot[j*3+2];
  138.                                         if( dot[j*3+2] > minmax[5] ) minmax[5] = dot[j*3+2];
  139.                                 }
  140.                         }
  141.  
  142.                         /* number Facetten. */
  143.                         Fread( source, (long) 2, &anz_facetten );
  144.  
  145.                         printf( "'%s' %d facettes: ", obj_name, anz_facetten );
  146.  
  147.                         /* memory for triangles. */
  148.                         if( ( facetten = malloc( (long) (anz_facetten * 8) ) ) == NULL )
  149.                         {        free( dot ); return( abbruch() ); }
  150.                         else
  151.                                 /* Facetten read in. */
  152.                                 Fread( source, (long) anz_facetten*4*2, facetten );
  153.  
  154.                         /* Facetten convert. */
  155.                         for( j = 0, buffer[0] = '\0' ; j<anz_facetten ; j++ )
  156.                         {
  157.                                 strcat( buffer, " triangle{" );
  158.  
  159.                                 /* points change... 2 places Nachkomma extend (/100), further
  160.                                          reduction must POV take (on)... */
  161.                                 for( m=0 ; m<3 ; m++ )
  162.                                 {
  163.                                         wandel[0] = (dot[facetten[j*4+m]*3+0]);                        /* x */
  164.                                         wandel[1] = (dot[facetten[j*4+m]*3+1]);                        /* y */
  165.                                         wandel[2] = (dot[facetten[j*4+m]*3+2]);                        /* z */
  166.                                         wandel[3] = abs( wandel[0] );                                                                                /* For Nachkomma... */
  167.                                         wandel[4] = abs( wandel[1] );
  168.                                         wandel[5] = abs( wandel[2] );
  169.                                         if( wandel[0] < 0 ) vorzeichen[0] = minus; else vorzeichen[0] = nullos;
  170.                                         if( wandel[1] < 0 ) vorzeichen[1] = minus; else vorzeichen[1] = nullos;
  171.                                         if( wandel[2] < 0 ) vorzeichen[2] = minus; else vorzeichen[2] = nullos;
  172.  
  173.                                         if( pov_mode == 1 )                                                                                /* POV vers.1 : No comma */
  174.                                                 sprintf( buffer2, "<%s%d.%d %s%d.%d %s%d.%d>",
  175.                                                                                         vorzeichen[0], wandel[3] / 100, wandel[3] % 100,
  176.                                                                                         vorzeichen[1], wandel[4] / 100, wandel[4] % 100,
  177.                                                                                         vorzeichen[2], wandel[5] / 100, wandel[5] % 100 );
  178.                                         else
  179.                                                 sprintf( buffer2, "<%s%d.%d,%s%d.%d,%s%d.%d>",
  180.                                                                                         vorzeichen[0], wandel[3] / 100, wandel[3] % 100,
  181.                                                                                         vorzeichen[1], wandel[4] / 100, wandel[4] % 100,
  182.                                                                                         vorzeichen[2], wandel[5] / 100, wandel[5] % 100 );
  183.  
  184.                                         strcat( buffer, buffer2 );
  185.                                 }
  186.  
  187.                                 strcat( buffer, buffer3 );
  188.  
  189.                                 if( j%10 == 0 )                                                                                                                        /* All 10 triangles write. */
  190.                                 {
  191.                                         printf( "." );
  192.                                         Fwrite( destin, strlen(buffer), buffer );
  193.                                         buffer[0] = '\0';
  194.                                 }
  195.                         }
  196.  
  197.                         if( strlen( buffer ) > 0 )                                                                                /* Restlichen points write. */
  198.                                 Fwrite( destin, strlen(buffer), buffer );
  199.  
  200.                         free(dot); free(facetten);
  201.                 }
  202.  
  203.                 puts( " done." );
  204.         }
  205.  
  206.         if( bounds != 0 )                                                                                                                                        /* <bounded_by> write. */
  207.         {
  208.                 wandel[0] = abs( minmax[0] ); wandel[1] = abs( minmax[1] );
  209.                 wandel[2] = abs( minmax[2] ); wandel[3] = abs( minmax[3] );
  210.                 wandel[4] = abs( minmax[4] ); wandel[5] = abs( minmax[5] );
  211.                 if( minmax[0] < 0 ) vorzeichen[0] = minus; else vorzeichen[0] = nullos;
  212.                 if( minmax[1] < 0 ) vorzeichen[1] = minus; else vorzeichen[1] = nullos;
  213.                 if( minmax[2] < 0 ) vorzeichen[2] = minus; else vorzeichen[2] = nullos;
  214.                 if( minmax[3] < 0 ) vorzeichen[3] = minus; else vorzeichen[3] = nullos;
  215.                 if( minmax[4] < 0 ) vorzeichen[4] = minus; else vorzeichen[4] = nullos;
  216.                 if( minmax[5] < 0 ) vorzeichen[5] = minus; else vorzeichen[5] = nullos;
  217.  
  218.                 if( pov_mode == 1 )
  219.                         sprintf( buffer, " bounded_by{box{<%s%d.%d %s%d.%d %s%d.%d><%s%d.%d %s%d.%d %s%d.%d>}}",
  220.                                                                 vorzeichen[0], wandel[0] / 100, wandel[0] % 100,
  221.                                                                 vorzeichen[2], wandel[2] / 100, wandel[2] % 100,
  222.                                                                 vorzeichen[4], wandel[4] / 100, wandel[4] % 100,
  223.                                                                 vorzeichen[1], wandel[1] / 100, wandel[1] % 100,
  224.                                                                 vorzeichen[3], wandel[3] / 100, wandel[3] % 100,
  225.                                                                 vorzeichen[5], wandel[5] / 100, wandel[5] % 100 );
  226.                 else
  227.                         sprintf( buffer, " bounded_by{box{<%s%d.%d,%s%d.%d,%s%d.%d><%s%d.%d,%s%d.%d,%s%d.%d>}}",
  228.                                                                 vorzeichen[0], wandel[0] / 100, wandel[0] % 100,
  229.                                                                 vorzeichen[2], wandel[2] / 100, wandel[2] % 100,
  230.                                                                 vorzeichen[4], wandel[4] / 100, wandel[4] % 100,
  231.                                                                 vorzeichen[1], wandel[1] / 100, wandel[1] % 100,
  232.                                                                 vorzeichen[3], wandel[3] / 100, wandel[3] % 100,
  233.                                                                 vorzeichen[5], wandel[5] / 100, wandel[5] % 100 );
  234.  
  235.                 Fwrite( destin, strlen( buffer ), buffer );
  236.                 buffer[0] = 13; buffer[1] = 10; buffer[2] = '\0';
  237.                 Fwrite( destin, 2, buffer );
  238.         }
  239.  
  240.         Fwrite( destin, strlen(buffer3), buffer3 );
  241.         Fclose( source ); Fclose( destin );
  242.         return( 0 );
  243. }
  244.  
  245. int abbruch()
  246. {
  247.         Fclose( source );
  248.         Fclose( destin );
  249.         return( -1 );                                                                /* Gemdosfehler: <0 */
  250. }
  251. ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙
  252. This  word-by-word   exchange   from  a   German   document, with   some
  253. adjustments  for  German idiom,  was  made with  a  registered  version 
  254. of Ruftrade2.                                                           
  255. ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙